home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 98
/
Skunkware 98.iso
/
src
/
mail
/
pine3.96.tar.gz
/
pine3.96.tar
/
pine3.96
/
pine
/
osdep
/
readfile.os2
< prev
next >
Wrap
Text File
|
1996-03-29
|
894b
|
42 lines
#line 2 "osdep/readfile.os2"
/*----------------------------------------------------------------------
Read whole file into memory
Args: filename -- path name of file to read
Result: Returns pointer to malloced memory with the contents of the file
or NULL
This won't work very well if the file has NULLs in it and is mostly
intended for fairly small text files.
----*/
char *
read_file(filename)
char *filename;
{
int nb;
char *buf =NULL;
char *p = tmp_20k_buf;
char tmp[1024];
FILE * fp = fopen(filename, "r");
if (fp){
while (fgets(tmp, sizeof tmp - 1, fp)!=NULL) {
int len = strlen(tmp);
if (p - tmp_20k_buf + len > 20480)
break;
memcpy(p, tmp, len);
p += len;
}
*p++ = '\0';
nb = p - tmp_20k_buf;
fclose(fp);
buf = fs_get(nb);
memcpy(buf, tmp_20k_buf, nb);
}
return buf;
}